//
//  HWMineBottomView.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/22.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWMineBottomView: UIView {

    var navView:HWMineNavView!
    var hotGamesView:HWMineHotGamesView!
    var navClick:((_ model:HWMineNavModel)->())?
    var itemButtonClick:((_ id:String)->())?
    var moreButtonClick:(()->())?
    var model:HWMineModel?{
        didSet {
            navView.model = model
            hotGamesView.model = model
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        self.addCorner(conrners: [.topLeft,.topRight], radius: 28*widthScale)
    }

}

extension HWMineBottomView {
    private func initUI() -> Void {
        self.backgroundColor = .colorWithHexString(hexString: "#F7F7F7")
        
        navView = HWMineNavView()
        addSubview(navView)
        
        navView.layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#C4C4C4", alpha: 0.14).cgColor
        navView.layer.shadowRadius = 6
        navView.layer.shadowOpacity = 1
        
        hotGamesView = HWMineHotGamesView()
        addSubview(hotGamesView)
        
        hotGamesView.layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#C4C4C4", alpha: 0.14).cgColor
        hotGamesView.layer.shadowRadius = 6
        hotGamesView.layer.shadowOpacity = 1
        
        navView.navClick = {
            mod in
            self.navClick?(mod)
        }
        
        hotGamesView.itemButtonClick = {
            id in
            self.itemButtonClick?(id)
        }
        
        hotGamesView.moreButtonClick = {
            self.moreButtonClick?()
        }
    }
    
    private func initFrame() -> Void {
        navView.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.right.equalTo(-20*widthScale)
            make.top.equalTo(16*widthScale)
        }
        
        hotGamesView.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.right.equalTo(-20*widthScale)
            make.top.equalTo(navView.snp.bottom).offset(10*widthScale)
            make.bottom.equalTo(-20)
        }
    }
}
